package com.dtjd.playcoinmonkey.activities;

import android.os.Build;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.bytedance.sdk.openadsdk.AdSlot;
import com.bytedance.sdk.openadsdk.TTAdDislike;
import com.bytedance.sdk.openadsdk.TTAdNative;
import com.bytedance.sdk.openadsdk.TTAdSdk;
import com.bytedance.sdk.openadsdk.TTNativeExpressAd;
import com.dtjd.playcoinmonkey.MyApplication;
import com.dtjd.playcoinmonkey.R;
import com.dtjd.playcoinmonkey.databinding.ActivityRecommendDetailBinding;

import java.util.List;
public class RecommendDetailActivity extends AppCompatActivity {
    private ActivityRecommendDetailBinding binding;
    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (android.R.id.home==item.getItemId()) finish();
        return super.onOptionsItemSelected(item);
    }
    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding= ActivityRecommendDetailBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        binding.recommendDetailTitle.setText(MyApplication.recommendBean.bp_title);
        binding.recommendDetailContent.setText(MyApplication.recommendBean.bp_content);
        binding.recommendDetailNickname.setText(MyApplication.recommendBean.wb_nickname);
        binding.recommendDetailTime.setText(MyApplication.recommendBean.time);
        binding.recommendDetailBack.setOnClickListener(view -> finish());
        if ( MyApplication.recommendBean.imgs.equals("")){
            binding.recommendDetailImg.setVisibility(View.GONE);
        }else {
            Glide.with(this).load(MyApplication.recommendBean.imgs).placeholder(R.drawable.loading).error(R.drawable.loaderr).into(binding.recommendDetailImg);
            binding.recommendDetailImg.setVisibility(View.VISIBLE);
        }
        TTAdNative mTTAdNative = TTAdSdk.getAdManager().createAdNative(this);
        mTTAdNative.loadBannerExpressAd(new AdSlot.Builder().setCodeId("946899285").setAdCount(1).setImageAcceptedSize(600, 300).setSupportDeepLink(true).build(), new TTAdNative.NativeExpressAdListener() {
            @Override
            public void onError(int i, String s) { }
            @Override
            public void onNativeExpressAdLoad(List<TTNativeExpressAd> ads) {
                if (ads == null || ads.size() == 0) return;
                TTNativeExpressAd ad = ads.get(0);
                ad.setExpressInteractionListener(new TTNativeExpressAd.ExpressAdInteractionListener() {
                    @Override
                    public void onAdClicked(View view, int type) {
                    }
                    @Override
                    public void onAdShow(View view, int type) {
                    }
                    @Override
                    public void onRenderFail(View view, String msg, int code) {
                    }
                    @Override
                    public void onRenderSuccess(View view, float width, float height) {
                        binding.recommendDetailBanner.setVisibility(View.VISIBLE);
                        binding.recommendDetailBanner.addView(view);
                    }
                });
                ad.setDislikeCallback(RecommendDetailActivity.this, new TTAdDislike.DislikeInteractionCallback() {
                    @Override
                    public void onShow() { }

                    @Override
                    public void onSelected(int i, String s, boolean b) {
                        binding.recommendDetailBanner.setVisibility(View.GONE);
                    }
                    @Override
                    public void onCancel() { }
                });
                ad.render();
            }
        });
    }
}